import * as THREE from "three";

const geometry = new THREE.BoxGeometry(300, 300, 300);
const material = new THREE.MeshLambertMaterial({
    color: 'orange'
});

const positions1 = geometry.attributes.position.clone();
for(let i = 0; i < positions1.count; i++) {
    positions1.setY(i, positions1.getY(i) * 2);    
}

const positions2 = geometry.attributes.position.clone();
for(let i = 0; i < positions2.count; i++) {
    positions2.setX(i, positions2.getX(i) * 2);    
}

geometry.morphAttributes.position = [positions1, positions2];
const mesh = new THREE.Mesh(geometry, material);
mesh.morphTargetInfluences = [0, 0];
mesh.name = 'test'
const track1 = new THREE.KeyframeTrack(`${mesh.name}.morphTargetInfluences[0]`, [0, 3], [0, 0.5]);
const track2 = new THREE.KeyframeTrack(`${mesh.name}.morphTargetInfluences[1]`, [3, 6], [0, 1]);
const clip = new THREE.AnimationClip('test', 6, [track1, track2]);
const mixer = new THREE.AnimationMixer(mesh);
const action = mixer.clipAction(clip);
action.play();

const clock = new THREE.Clock();
function render() {
    const delta = clock.getDelta();
    mixer.update(delta);
    requestAnimationFrame(render);
}
render();


export { mesh };


